package com.cicigodd.brick.plug.system.role.controller;

import com.cicigodd.brick.plug.annotation.repeatsubmit.RepeatSubmit;
import com.cicigodd.brick.plug.annotation.resource.DeleteResource;
import com.cicigodd.brick.plug.annotation.resource.PutResource;
import com.cicigodd.brick.plug.common.response.PageResult;
import com.cicigodd.brick.plug.common.response.Result;
import com.cicigodd.brick.plug.common.response.ResultGenerator;
import com.cicigodd.brick.plug.annotation.resource.PostResource;
import com.cicigodd.brick.plug.annotation.resource.GetResource;
import com.cicigodd.brick.plug.system.role.request.SysRoleUserAddRequest;
import com.cicigodd.brick.plug.system.role.request.SysRoleUserDeleteRequest;
import com.cicigodd.brick.plug.system.role.request.SysRoleUserDetailRequest;
import com.cicigodd.brick.plug.system.role.request.SysRoleUserEditRequest;
import com.cicigodd.brick.plug.system.role.request.SysRoleUserListRequest;
import com.cicigodd.brick.plug.system.role.response.SysRoleUserDetailResponse;
import com.cicigodd.brick.plug.system.role.response.SysRoleUserListResponse;
import com.cicigodd.brick.plug.system.role.service.SysRoleUserService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;

@ApiIgnore
@Api(tags = "角色用户关联")
@RestController
public class SysRoleUserController {

    @Resource
    private SysRoleUserService sysRoleUserService;

    @RepeatSubmit
    @ApiOperation(value = "角色用户关联添加", notes = "角色用户关联添加")
    @PostResource(name = "角色用户关联添加", path = "/sysRoleUser/add")
    public Result add(@RequestBody @Validated SysRoleUserAddRequest sysRoleUserAddRequest) {
        sysRoleUserService.add(sysRoleUserAddRequest);
        return ResultGenerator.successResult();
    }


    @ApiOperation(value = "角色用户关联删除", notes = "根据id删除")
    @DeleteResource(name = "角色用户关联删除", path = "/sysRoleUser/delete")
    public Result delete(@Validated SysRoleUserDeleteRequest sysRoleUserDeleteRequest) {
        sysRoleUserService.delete(sysRoleUserDeleteRequest);
        return ResultGenerator.successResult();
    }


    @ApiOperation(value = "角色用户关联编辑", notes = "角色用户关联编辑")
    @PutResource(name = "角色用户关联编辑", path = "/sysRoleUser/edit")
    public Result edit(@RequestBody @Validated SysRoleUserEditRequest sysRoleUserEditRequest) {
        sysRoleUserService.edit(sysRoleUserEditRequest);
        return ResultGenerator.successResult();
    }


    @ApiOperation(value = "角色用户关联详情", notes = "根据id查询")
    @GetResource(name = "角色用户关联详情", path = "/sysRoleUser/detail")
    public Result<SysRoleUserDetailResponse> detail(SysRoleUserDetailRequest sysRoleUserDetailRequest) {
        SysRoleUserDetailResponse detail = sysRoleUserService.detail(sysRoleUserDetailRequest);
        return ResultGenerator.successResult(detail);
    }


    @ApiOperation(value = "角色用户关联分页列表", notes = "角色用户关联分页列表")
    @GetResource(name = "角色用户关联分页列表", path = "/sysRoleUser/list")
    public Result<PageResult<SysRoleUserListResponse>> list(SysRoleUserListRequest sysRoleUserListRequest) {
        PageResult<SysRoleUserListResponse> pageList =  sysRoleUserService.list(sysRoleUserListRequest);
        return ResultGenerator.successResult(pageList);
    }
}
